package com.nanjia.boot.myflow.deliveryaddressflow.controller;

import com.nanjia.boot.myflow.deliveryaddressflow.service.DeliveryAddressFlowService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.nanjia.boot.myflow.deliveryaddressflow.model.form.DeliveryAddressFlowForm;
import com.nanjia.boot.myflow.deliveryaddressflow.model.query.DeliveryAddressFlowQuery;
import com.nanjia.boot.myflow.deliveryaddressflow.model.vo.DeliveryAddressFlowVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.nanjia.boot.common.result.PageResult;
import com.nanjia.boot.common.result.Result;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;

/**
 * 收货/收票信息流水前端控制层
 *
 * @author 周洋
 * @since 2025-07-29 16:44
 */
@Tag(name = "收货/收票信息流水接口")
@RestController
@RequestMapping("/api/v1/delivery-address-flow")
@RequiredArgsConstructor
public class DeliveryAddressFlowController  {

    private final DeliveryAddressFlowService deliveryAddressFlowService;

    @Operation(summary = "收货/收票信息流水分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ss.hasPerm('deliveryAddressFlow:delivery-address-flow:query')")
    public PageResult<DeliveryAddressFlowVO> getDeliveryAddressFlowPage(DeliveryAddressFlowQuery queryParams ) {
        IPage<DeliveryAddressFlowVO> result = deliveryAddressFlowService.getDeliveryAddressFlowPage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "新增收货/收票信息流水")
    @PostMapping
    @PreAuthorize("@ss.hasPerm('deliveryAddressFlow:delivery-address-flow:add')")
    public Result<Void> saveDeliveryAddressFlow(@RequestBody @Valid DeliveryAddressFlowForm formData ) {
        boolean result = deliveryAddressFlowService.saveDeliveryAddressFlow(formData);
        return Result.judge(result);
    }

    @Operation(summary = "获取收货/收票信息流水表单数据")
    @GetMapping("/{id}/form")
    @PreAuthorize("@ss.hasPerm('deliveryAddressFlow:delivery-address-flow:edit')")
    public Result<DeliveryAddressFlowForm> getDeliveryAddressFlowForm(
        @Parameter(description = "收货/收票信息流水ID") @PathVariable Long id
    ) {
        DeliveryAddressFlowForm formData = deliveryAddressFlowService.getDeliveryAddressFlowFormData(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改收货/收票信息流水")
    @PutMapping(value = "/{id}")
    @PreAuthorize("@ss.hasPerm('deliveryAddressFlow:delivery-address-flow:edit')")
    public Result<Void> updateDeliveryAddressFlow(
            @Parameter(description = "收货/收票信息流水ID") @PathVariable Long id,
            @RequestBody @Validated DeliveryAddressFlowForm formData
    ) {
        boolean result = deliveryAddressFlowService.updateDeliveryAddressFlow(id, formData);
        return Result.judge(result);
    }

    @Operation(summary = "删除收货/收票信息流水")
    @DeleteMapping("/{ids}")
    @PreAuthorize("@ss.hasPerm('deliveryAddressFlow:delivery-address-flow:delete')")
    public Result<Void> deleteDeliveryAddressFlows(
        @Parameter(description = "收货/收票信息流水ID，多个以英文逗号(,)分割") @PathVariable String ids
    ) {
        boolean result = deliveryAddressFlowService.deleteDeliveryAddressFlows(ids);
        return Result.judge(result);
    }
}
